﻿@inherits IdComponentBase

<AuthorizeView>
    <Authorized>
        <div class="dropdown dropdown-logout">
             <a class="dropdown-toggle" data-bs-toggle="dropdown" href="#" id="@Id" aria-expanded="false">
                <img class="logout-avatar" alt="avatar" src="_content/BPM.Web.Shared/images/logo.png">
                @context.User.FindFirst(x=>x.Type=="Name")?.Value
            </a>

            <div class="dropdown-menu dropdown-menu-end border-primary shadow" aria-labelledby="@Id">
                <div class="dropdown-item dropdown-user bg-primary">
                    <div class="d-flex flex-fill align-items-center">
                        <img alt="avatar" src="_content/BPM.Web.Shared/images/logo.png" style="border-radius: 50%;">
                        <div class="flex-fill">
                            <div class="logout-dn">@context.User.FindFirst(x=>x.Type=="Name")?.Value</div>
                            <div class="logout-un">@context.User.FindFirst(x=>x.Type=="Account")?.Value</div>
                        </div>
                    </div>
                </div>

                <div class="dropdown-item">
                    <a href="/"><i class="fa fa-tachometer fa-fw"></i><span class="nav-link-text">返回主页</span></a>

                    <a href="/Admin/Account"><i class="fa fa-user fa-fw"></i><span class="nav-link-text">账户设置</span></a> 

                    <a href="/api/index.html"><i class="fa fa-file-text fa-fw"></i><span class="nav-link-text">后端接口</span></a>

                    <a @onclick="@Logout" ><i class="fa fa-sign-out fa-fw"></i><span class="nav-link-text">注销登录</span></a>         
                </div>
            </div>
        </div>
    </Authorized>
</AuthorizeView>



@code {
    /// <summary>
    /// 当前Token信息
    /// </summary>
    [CascadingParameter]
    private TokenContext? Context { get; set; }

    /// <summary>
    /// 当前会话状态
    /// </summary>
    [CascadingParameter]
    public SessionState State { get; set; } = new();

    /// <summary>
    /// 登出系统
    /// </summary>
    /// <returns></returns>
    public void Logout()
    {
        Context!.UpdateToken(false, null, null);
        State.Reload(false);
    }
}
